﻿

//物品记录

var mCloseEvidenceList_Query = {};//查询条件

$(function () {

    var args = getUrlArgs();



    

    $("#cmbState").combobox({
        valueField: 'Id',
        textField: 'Name',
        editable: false,
        onSelect: function (record) { mCloseEvidenceList_Query.State = record.Id; }
    });


    $("#cmbOrg").combobox({
        valueField: 'Id',
        textField: 'Name',
        editable: false,
        panelHeight: 120,
        onSelect: function (record) { mCloseEvidenceList_Query.DeptId = record.Id; }
    });

    setStateToCmb();

    gLoadAllDepts(function (orgs) {
        var allOrg = {};
        allOrg.Id = 0;
        allOrg.Name = "全部";
        orgs.splice(0, 0, allOrg);
        $('#cmbOrg').combobox('loadData', orgs);
    }, false);

    packQuery();//打包初始查询条件

    $('#closeEvidenceDataGrid').datagrid({
        url: '/Case/LoadCloseEvidenceSimpleList',
        fitColumns: false,
        rownumbers: true,
        resizable: true,
        pagination: true,
        pageNumber: 1,
        pageSize: 20,
        nowrap: false,
        height: 540,
        idField: 'Id',
        toolbar: '#closeEvidenceToolbar',
        queryParams: { 'closeEvidenceQuery': JSON.stringify(mCloseEvidenceList_Query) },
        singleSelect: true,
        columns: [[
               { title: 'Id', field: 'Id', align: 'center', width: 10, hidden: true },
               { title: '状态', field: 'IsCheck', align: 'center', width: 100, formatter: getStateName },
               { title: '案件编号', field: 'Number', align: 'center', width: 100 },
               { title: '记录日期', field: 'BillTime', align: 'center', width: 100, formatter: getFormatDate },
               { title: '办案单位', field: 'TransferDeptName', align: 'center', width: 150, formatter: gFormatDeptNameForColumn },
               { title: '办案人', field: 'TransferName', align: 'center', width: 80 },
               { title: '保管部门', field: 'ManageDeptName', align: 'center', width: 200, formatter: gFormatDeptNameForColumn }
        ]]
    });


});

function setStateToCmb() {
    var states = [];

    var state1 = {};
    state1.Id = -1;
    state1.Name = "全部";
    
    var state2 = {};
    state2.Id = 0;
    state2.Name = "可以结案";

    var state3 = {};
    state3.Id = 1;
    state3.Name = "已结案";
    states.push(state1, state2, state3);

    $('#cmbState').combobox('loadData', states);

}

function getStateName(value, rowData, index) {
    if (!value && !rowData.IsFinish) {
        return '未审核';
    }
    else if (value && !rowData.IsFinish) {
        if (rowData.StockState == 1)
            return "部分入库";
        else if (rowData.StockState == 2)
            return "全部入库";
        else if (rowData.StockState == 4)
            return "部分调查入库";
        else if (rowData.StockState == 8)
            return "全部调查入库";
        else if (rowData.StockState == 16)
            return "部分出库";
        else if (rowData.StockState == 32)
            return "全部出库";
        else if (rowData.StockState == 64)
            return "部分调查出库";
        else if (rowData.StockState == 128)
            return "全部调查出库";
        else if (rowData.StockState == 256)
            return "结案";
        else
            return "未入库"

    } else if (rowData.IsFinish) {
        return '结案';
    } else {
        return '状态未定义,value=' + value + "  ,IsFinish= " + rowData.IsFinish;
    }

}

function getFormatDate(value, rowData, index) {
    if (value) {
        return gFormatDateFormCSharp(value, 'yyyy-MM-dd');
    }
}

function closeEvidenceAction() {
    var row = $("#closeEvidenceDataGrid").datagrid("getSelected");
    var id = 0;
    if (row) {
        if (row.IsFinish) {
            $.messager.alert('提示', '物品单已经结案!');
        } else if (row.StockState != 32){
            $.messager.alert('提示', '物品单还未完全出库,不能结案!');
        } else if (row.StockState == 32) {
            $.ajax({
                url: "/Case/CloseEvidenceBill",
                type: "POST",
                dataType: "json",
                data: { "billId": row.Id },
                async: false,
                success: function (req) {
                    if (req.IsSuccess) {
                        $.messager.alert('提示', '结案成功!');
                        loadCloseEvidences();
                    } else {
                        $.messager.alert('提示', '结案失败! '+req.Data);
                    }
                }
            });
        }
    } else {
        $.messager.alert('提示', '请选择物品单!');
    }
}

//打包参数
function packQuery() {
    mCloseEvidenceList_Query.CaseNo = $('#txtCaseNo').val();
    mCloseEvidenceList_Query.EvidenceName = $('#txtEvidenceName').val();
}

//读取所有物品单据
function loadCloseEvidences() {
    try {
        packQuery();
        var json = JSON.stringify(mCloseEvidenceList_Query);
        $('#closeEvidenceDataGrid').datagrid('reload', { 'closeEvidenceQuery': json });

    } catch (ex) {
        alert(ex);
    }
}

function seachCloseEvidenceAction() {
    loadCloseEvidences();
}

